//
//  CuoTiLvCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/6/20.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CuoTiLvCell.h"

@implementation CuoTiLvCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    UILabel *contLab = [UILabel new];
    CGFloat W = 1.0/5;
    NSArray *array = @[@"学生",@"学号",@"考试次数",@"上升名次",@"操作"];
    for (int i = 0; i<5; i++) {
        if (i == 0) {
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            contLab = label;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@0);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
        } else if(i==4){
            UILabel *label = [[UILabel alloc]init];
            label.userInteractionEnabled = YES;
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            [label addSubview:self.caoZuoButton];
            [_caoZuoButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.equalTo(@60);
                make.centerX.equalTo(label.mas_centerX);
                make.centerY.equalTo(label.mas_centerY);
                make.height.equalTo(@20);
            }];
        }else{
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
        }
    }
    
}
- (void)reloadViewArray:(NSArray *)array{
    for (int i =0;i<array.count;i++) {
        UILabel *label = (UILabel *)[self viewWithTag:20+i];
        label.text = array[i];
    }
}
- (UIButton *)caoZuoButton{
    if (!_caoZuoButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"详情" forState:0];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickDetail:) forControlEvents:UIControlEventTouchUpInside];
        _caoZuoButton = button;
    }
    return _caoZuoButton;
}
- (void)clickDetail:(UIButton *)sender{
    self.block(self.index);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

//- (void)drawRect:(CGRect)rect{
//    UIBezierPath *path = [[UIBezierPath alloc]init];
//    [path moveToPoint:CGPointMake(0,50)];
//    [path addLineToPoint:CGPointMake(self.frame.size.width, 50)];
//    [LINCOLOR set];
//    [path stroke];
//    CGFloat W = self.frame.size.width/5.0;
//    for (int i = 1; i<5; i++) {
//        UIBezierPath *pathNext =[[UIBezierPath alloc]init];
//        [pathNext moveToPoint:CGPointMake(W*i,0)];
//        [pathNext addLineToPoint:CGPointMake(W*i, 50)];
//        [LINCOLOR set];
//        [pathNext stroke];
//    }
//}

@end
